package com.v.air.app.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.res.Resources;

import com.v.air.app.R;
import com.v.air.app.tools.PreferencesTool;

public class DeviceBean implements Serializable {
	private int id;
	private String name;
	private float pm;
	private float temperature;
	private float humidity;
	private float ppm;
	private float tvoc;

	public DeviceBean() {
	}

	public DeviceBean(float pm, float temperature, float humidity, float ppm,
			float tvoc) {
		this.pm = pm;
		this.temperature = temperature;
		this.humidity = humidity;
		this.ppm = ppm;
		this.tvoc = tvoc;
	}

	public DeviceBean(int id, String name, float pm, float temperature,
			float humidity, float ppm, float tvoc) {
		this.id = id;
		this.name = name;
		this.pm = pm;
		this.temperature = temperature;
		this.humidity = humidity;
		this.ppm = ppm;
		this.tvoc = tvoc;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public float getPm() {
		return pm;
	}

	public void setPm(float pm) {
		this.pm = pm;
	}

	public float getTemperature() {
		return temperature;
	}

	public void setTemperature(float temperature) {
		this.temperature = temperature;
	}

	public float getHumidity() {
		return humidity;
	}

	public void setHumidity(float humidity) {
		this.humidity = humidity;
	}

	public float getPpm() {
		return ppm;
	}

	public void setPpm(float ppm) {
		this.ppm = ppm;
	}

	public float getTvoc() {
		return tvoc;
	}

	public void setTvoc(float tvoc) {
		this.tvoc = tvoc;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public static void clear(Context context) {
		PreferencesTool.putFloat(context, "pm", 0);
		PreferencesTool.putFloat(context, "co2", 0);
		PreferencesTool.putFloat(context, "tvoc", 0);
		PreferencesTool.putFloat(context, "temperature", 0);
		PreferencesTool.putFloat(context, "humidity", 0);
	}

	public static List<DeviceBean> deviceList() {
		List<DeviceBean> list = new ArrayList<DeviceBean>();
		list.add(new DeviceBean(1, "办公室", 25f, 18f, 37f, 480f, 0.21f));
		list.add(new DeviceBean(2, "会议室", 22f, 15f, 46f, 630f, 0.25f));
		list.add(new DeviceBean(3, "大厅", 75f, 19f, 55f, 580f, 0.23f));
		list.add(new DeviceBean(4, "前台", 14f, 13f, 50f, 680f, 0.22f));
		list.add(new DeviceBean(5, "财务室", 18f, 14f, 60f, 280f, 0.24f));
		list.add(new DeviceBean(6, "休息室", 67f, 19f, 57f, 880f, 0.28f));
		return list;
	}

	// PM2.5状态
	public static String getPMstate(float num, Resources resources) {
		String str = "";
		if (num <= 35) {
			str = resources.getString(R.string.pm_state_optimal);
		} else if (num <= 75) {
			str = resources.getString(R.string.pm_state_good);
		} else if (num <= 115) {
			str = resources.getString(R.string.pm_state_mild);
		} else if (num <= 150) {
			str = resources.getString(R.string.pm_state_moderate);
		} else if (num <= 250) {
			str = resources.getString(R.string.pm_state_severe);
		} else {
			str = resources.getString(R.string.pm_state_serious);
		}
		return str;
	}

	// 温度状态
	public static String getTemperatureState(float number, Resources resources) {
		String str = "";
		if (number < 15) {
			str = resources.getString(R.string.temperature_state_01);
		} else if (number <= 18) {
			str = resources.getString(R.string.temperature_state_02);
		} else if (number <= 25) {
			str = resources.getString(R.string.temperature_state_03);
		} else if (number <= 30) {
			str = resources.getString(R.string.temperature_state_04);
		} else {
			str = resources.getString(R.string.temperature_state_05);
		}
		return str;
	}

	// 湿度状态
	public static String getHumidityState(float number, Resources resources) {
		String str = "";
		if (number < 40) {
			str = resources.getString(R.string.humidity_state_01);
		} else if (number <= 65) {
			str = resources.getString(R.string.humidity_state_02);
		} else {
			str = resources.getString(R.string.humidity_state_03);
		}
		return str;
	}

	// 二氧化碳 状态
	public static String getPpmState(float number, Resources resources) {
		String str = "";
		if (number < 1000) {
			str = resources.getString(R.string.ppm_state_01);
		} else if (number < 2000) {
			str = resources.getString(R.string.ppm_state_02);
		} else if (number < 5000) {
			str = resources.getString(R.string.ppm_state_03);
		} else {
			str = resources.getString(R.string.ppm_state_04);
		}
		return str;
	}

	// TVOC状态
	public static String getTvocState(float number, Resources resources) {
		String str = "";
		if (number <= 0.3) {
			str = resources.getString(R.string.tvoc_state_01);
		} else if (number <= 0.6) {
			str = resources.getString(R.string.tvoc_state_02);
		} else {
			str = resources.getString(R.string.tvoc_state_03);
		}
		return str;
	}

	public static int getPMstateColor(float num, Resources resources) {
		int color = R.color.pm_color_optimal;
		if (num >= 250) {
			color = resources.getColor(R.color.pm_color_serious);
		} else if (num >= 150) {
			color = resources.getColor(R.color.pm_color_severe);
		} else if (num >= 115) {
			color = resources.getColor(R.color.pm_color_moderate);
		} else if (num >= 75) {
			color = resources.getColor(R.color.pm_color_mild);
		} else if (num >= 35) {
			color = resources.getColor(R.color.pm_color_good);
		} else {
			color = resources.getColor(R.color.pm_color_optimal);
		}
		return color;
	}
}
